<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/9/16
 * Time: 11:30
 */

namespace app\admin\controller;

use app\service\IncomeService;
use app\service\StatisticalService;
use think\Db;

/**
 * 收支统计.
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月22日10:57:35
 */
class IncomeData extends Common
{
    /**
     * 构造方法.
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月22日10:57:59
     */
    public function __construct()
    {
        // 调用父类前置方法
        parent::__construct();

        // $this->IsLogin();
    }

    /**
     * [Index 收支列表]
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月22日10:57:59
     */
    public function Index()
    {


        if ('ajax' != input('get.action')) {


            return $this->fetch();
        } else {
            $params = input();

            // 条件
            $where = IncomeService::ListWhere($params['param']);

            // 参数
            $data_params  = [
                'where' => $where,
                'page' => true,
                'field' => '*',
                'number' => 10,
                'table'=>'log_income'
            ];

            $re= IncomeService::DataList($data_params);

           // dump($re);exit;
            //dump($where);exit;
            $re= IncomeService::DealWith($re);
            $total=IncomeService::DataTotal('log_income',$where);
            $datatotal = StatisticalService::IncomeTotal();
            $tmptotal=IncomeService::IncomeTotal($where);
            //dump($total);exit;
            return ['code' => 0, 'msg' => '','count'=>$total, 'datacount' => $datatotal, 'data' => $re,'tempcount'=>$tmptotal];
        }
    }
    /**
     * [SaveData 添加备注]
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月22日10:57:59
     */
    public function SaveData(){
        $params=$this->data_post;
        //var_dump($params);exit;

        Db::name('log_income')->where(['id'=>$params])->update($params);
        return DataReturn('修改成功', 0);
    }
}